﻿Public Class DRUGALERT
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGALERT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASALERT()

        DesignForm(Me)
        DesignGrid(masalertGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASALERT()
        Dim objSelectDataMASALERT As New masalert
        Dim MASALERT As DataTable
        MASALERT = connect.GetTable(objSelectDataMASALERT.selectMasalert_)
        masalertGrid.PrimaryGrid.DataSource = MASALERT
    End Sub

    Private Sub masalertGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles masalertGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        ALERTTYPETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการเตือน").Value()
        ALERTNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("การเตือน").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masalertStatusChk.Checked = True
        Else
            masalertStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("masalert", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "ALERTTYPE", ALERTTYPETxt.Text)
    End Sub

    Private Sub addMasalert_Click(sender As Object, e As EventArgs) Handles addMasalert.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If ALERTNAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masalert
                    objInsertData.ALERTNAME_ = ALERTNAMETxt.Text
                    objInsertData.STATUS_ = masalertStatusChk.Checked
                    objInsertData.insertMasalertData()

                    SelectDatagridMASALERT()

                    ALERTTYPETxt.Text = ""
                    ALERTNAMETxt.Text = ""
                    masalertStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasalert_Click(sender As Object, e As EventArgs) Handles editMasalert.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If ALERTTYPETxt.Text.ToString.Length > 0 And ALERTNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลการแจ้งเตือนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masalert
                        objEditData.ALERTTYPE_ = ALERTTYPETxt.Text
                        objEditData.ALERTNAME_ = ALERTNAMETxt.Text
                        objEditData.STATUS_ = masalertStatusChk.Checked
                        objEditData.editMasalertData()

                        SelectDatagridMASALERT()

                        ALERTTYPETxt.Text = ""
                        ALERTNAMETxt.Text = ""
                        masalertStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masalert")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masalert")
        nextform.ShowDialog()
    End Sub
End Class